﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Deployment.Data.UI.Dialogs.Deploy
{
    /// <summary>
    /// Interaction logic for DeploymentBuilderDialog.xaml
    /// </summary>
    public partial class DeploymentBuilderDialog : Window
    {
        public static readonly DependencyProperty EnvironmentsProperty =
            DependencyProperty.Register("Environments",
                typeof(Data.Environment.EnvironmentsFile),
                typeof(DeploymentBuilderDialog));

        public event DependencyPropertyChangedEventHandler PropertyChanged;
        private void SetValueDp(DependencyProperty property, object value)
        {
            SetValue(property, value);
            if (PropertyChanged != null)
                PropertyChanged(this, new DependencyPropertyChangedEventArgs());
        }

        
        public DeploymentBuilderDialog(string deploymentFile = null)
        {
            InitializeComponent();
            Data.Deploy.DeploymentFile dFile = new Data.Deploy.DeploymentFile();
            if (!string.IsNullOrEmpty(deploymentFile))
            {
                dFile = Data.Deploy.DeploymentFile.LoadFromFile(deploymentFile);
                this.Control.DeploymentFilePathText = deploymentFile;
            }
            this.DataContext = dFile;
        }

        public Data.Environment.EnvironmentsFile Environments
        {
            get { return (Data.Environment.EnvironmentsFile)GetValue(EnvironmentsProperty); }
            set 
            { 
                SetValueDp(EnvironmentsProperty, value);
                Control.Environments = value;
            }
        }

        public string DeploymentFile { get; set; }
    }
}
